package flc.ast.adapter;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ConvertUtils;
import com.blankj.utilcode.util.FileUtils;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import flc.ast.R;
import flc.ast.bean.ApkBean;
import flc.ast.utils.MyUtils;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;

public class SearchApkAdapter extends StkProviderMultiAdapter<ApkBean> {

    public SearchApkAdapter() {
        addItemProvider(new StkSingleSpanProvider<>(82));
        addItemProvider(new SearchApkProvider());
    }

    private class SearchApkProvider extends BaseItemProvider<ApkBean> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_search_apk;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, ApkBean bean) {
            baseViewHolder.setText(R.id.tvSearchApkItemName, AppUtils.getAppName(bean.pkgName));
            baseViewHolder.setText(R.id.tvSearchApkItemSize, ConvertUtils.byte2FitMemorySize(MyUtils.getAppSize(getContext(), bean.pkgName), 0));
            baseViewHolder.setImageDrawable(R.id.ivSearchApkItemImg, AppUtils.getAppIcon(bean.pkgName));
        }
    }


}
